package com.baidu.structure.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.baidu.structure.R;
import com.baidu.structure.activity.ChatActivity;
import com.baidu.structure.constants.Tags;
import com.baidu.structure.utils.JumpUtils;
import com.hyphenate.chat.EMConversation;
import com.hyphenate.easeui.EaseConstant;
import com.hyphenate.easeui.ui.EaseConversationListFragment;

/**
 * Created by sunmo on 2016/11/30.
 */
public class ConversationFragment extends Fragment {
    private EaseConversationListFragment conversationListFragment;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_conversation, container, false);
        init();
        return v;
    }

    private void init() {
        conversationListFragment = new EaseConversationListFragment();
        getChildFragmentManager().beginTransaction().add(R.id.conversation_container, conversationListFragment, Tags.FRAGEMNT_CONVERSATION_LIST).commit();
        conversationListFragment.setConversationListItemClickListener(new EaseConversationListFragment.EaseConversationListItemClickListener() {
            @Override
            public void onListItemClicked(EMConversation emConversation) {
                Intent intent=new Intent(getActivity(),ChatActivity.class);
                intent.putExtra(EaseConstant.EXTRA_USER_ID,emConversation.getUserName());
                JumpUtils.simpleJump(getActivity(),intent);
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        conversationListFragment.hideTitleBar();

    }
}
